package org.itsolutions.javaBackup.spi;

import static org.itsolutions.javaBackup.spi.EModule.FTP;
import static org.itsolutions.javaBackup.spi.EModule.GUI_WEB;

import java.util.Arrays;
import java.util.List;

import org.itsolutions.javaBackup.properties.IPropertyEnum;


/**
 * 
 * @author Tomas Fecko
 */
public enum ENodeFunctionality implements IPropertyEnum<ENodeFunctionality> {
	
	//CHECKSTYLE:OFF
	/**
	 * Functionality of ftp backup engine.
	 */
	FTP_BACKUP(Arrays.asList(new EModule[]{FTP, GUI_WEB})),
	/**
	 * All of the above functionalities - default.
	 */
	ALL(Arrays.asList(EModule.values()));
	//CHECKSTYLE:ON
	
	private final List<EModule> mModulesNeeded;
	
	/**
	 * 
	 * @param pModulesNeeded
	 */
	private ENodeFunctionality(List<EModule> pModulesNeeded) {
		mModulesNeeded = pModulesNeeded;
	}

	@Override
	public ENodeFunctionality getValue(String pValueStr) {
		if (pValueStr != null) {
			for (ENodeFunctionality value : values()) {
				if (value.name().equalsIgnoreCase(pValueStr.trim())) {
					return value;
				}
			}
		}
		return null;
	}
	
	/**
	 * 
	 * @param pModule module
	 * @return true, if functionality needs that module
	 */
	public boolean needsModule(EModule pModule) {
		return mModulesNeeded.contains(pModule);
	}
	
	/**
	 * 
	 * @return requiered modules
	 */
	public List<EModule> getRequieredModules() {
		return mModulesNeeded;
	}
}





